package com.neuedu.corejava.ch10;

import java.util.TreeSet;

public class TreeSetClass {

	public static void main(String[] args) {
		
		//TreeSet保存的数据类型需要实现 java.lang.Comparable接口
		//在保存数据时进行类型检查，
		//如果没有实现Comparable接口会报类型转换异常java.lang.ClassCastException
		TreeSet<Computer> treeSet=new TreeSet<Computer>();
		treeSet.add(new Computer("HP1",5000));
		treeSet.add(new Computer("HP3",5000));
		treeSet.add(new Computer("HP2",5000));
		treeSet.add(new Computer("HW6",5200));
		treeSet.add(new Computer("HW2",5200));
		treeSet.add(new Computer("DELL4",5500));
		treeSet.add(new Computer("DELL2",5500));
		
		Computer computer=treeSet.first();
		Computer computer2=treeSet.last();
		System.out.println(computer);
		System.out.println(computer2);
		
		//以队列形式进行操作
		//computer=treeSet.pollFirst();
		computer=treeSet.pollLast();
		while(computer!=null) {
			System.out.println(computer);
			computer=treeSet.pollFirst();
		}
		
		
		
		
	}

}
